package evs.testbrp;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import evs.brp.ClientRequestHandler;
import evs.brp.RemotingErrorException;

public class TestClient {
	
	private Log log = LogFactory.getLog(ClientRequestHandler.class);
	
	public void printSyntax() {
		System.err.println("Syntax: TestClient ServerURI");
		System.exit(-1);
	}	
	
	public static void main(String[] args) {
		TestClient testClient = new TestClient();
		
		if(args.length != 1)
			testClient.printSyntax();
		
		testClient.testClientProxy(args[0]);
	}
	
	public void testClientProxy(String serverUri) {
		
		GeneratedClientProxy clientProxy = new GeneratedClientProxy();
		
		try {			
			clientProxy.bind(new URI(serverUri));
			
			String message = clientProxy.echo("message");
			log.info("Result of echo method: " + message);
			
			Double addResult = clientProxy.add(new Integer(3), new Long(4));
			log.info("Result of add method: " + addResult);
			
			Date serverTime = clientProxy.getServerTime();
			log.info("Result of getServerTime method: " + serverTime);
			
			clientProxy.unbind();			
		} 
		catch (URISyntaxException use) {
			log.error(use);
		} 
		catch (RemotingErrorException exc) {
			log.error(exc);
		}
	}
}
